import request from './request'

const api = {
  //类型获取
  getType: () => request({
    method: 'get',
    url: '/api/categoty',
  }),

  // 博客
  getBlog: (params) => request({
    method: 'get',
    url: '/api/blog',
    params
  }),
  getBlogDetail: (params) => request({
    method: 'get',
    url: '/api/blog/detail',
    params
  }),
  getBlogSearch: (params) => request({
    method: 'get',
    url: '/api/blog/search',
    params
  }),
  setBlogLike: (data) => request({
    method: 'post',
    url: '/api/blog/like',
    data
  }),

  // 技能
  getSkill: (params) => request({
    method: 'get',
    url: '/api/skill',
    params
  }),

  // 经验
  getExp: (params) => request({
    method: 'get',
    url: '/api/exp',
    params
  }),

  // 站长
  getWebmaster: () => request({
    method: 'get',
    url: '/api/webmaster'
  }),
  getUser: (params) => request({
    method: 'get',
    url: '/api/user',
    params
  })
}

function install(Vue) {
  Vue.prototype.$request = request;
  Vue.prototype.$api = api;

  // 设置时间戳转换
  Vue.prototype.timestampToDate = function (timestamp) {
    let date;
    if (timestamp.length == 10) {
      date = new Date(parseInt(timestamp) * 1000);
    } else if (timestamp.length == 13) {
      date = new Date(parseInt(timestamp));
    }


    let y = date.getFullYear();
    let m = date.getMonth() + 1;
    let d = date.getDate();
    let h = date.getHours();
    let minute = date.getMinutes();
    let second = date.getSeconds();
    m = m < 10 ? '0' + m : m;
    d = d < 10 ? '0' + d : d;
    minute = minute < 10 ? '0' + minute : minute;
    second = second < 10 ? '0' + second : second;

    return `${y}-${m}-${d} ${h}:${minute}:${second}`;
  }
}

export default {
  install
}